home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / ld / emultempl / gld960c.em < prev    next >
Encoding:
Text File  |  1996-07-04  |  3.9 KB  |  178 lines

  1. # This shell script emits a C file. -*- C -*-
  2. # It does some substitutions.
  3. cat >e${EMULATION_NAME}.c <<EOF
  4. /* Copyright (C) 1991, 1993 Free Software Foundation, Inc.
  5.  
  6. This file is part of GLD, the Gnu Linker.
  7.  
  8. GLD is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 1, or (at your option)
  11. any later version.
  12.  
  13. GLD is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GLD; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  21.  
  22. /* 
  23.  * emulate the Intels port of  gld
  24.  */
  25.  
  26.  
  27. #include "bfd.h"
  28. #include "sysdep.h"
  29. #include "libiberty.h"
  30. #include "bfdlink.h"
  31.  
  32. #include "ld.h"
  33. #include "ldemul.h"
  34. #include "ldfile.h"
  35. #include "ldmisc.h"
  36. #include "ldmain.h"
  37.  
  38. #ifdef GNU960
  39.  
  40. static void
  41. gld960_before_parse()
  42. {
  43.   static char *env_variables[] = { "G960LIB", "G960BASE", 0 };
  44.   char **p;
  45.   char *env ;
  46.  
  47.   for ( p = env_variables; *p; p++ ){
  48.     env =  (char *) getenv(*p);
  49.     if (env) {
  50.       ldfile_add_library_path (concat (env,
  51.                        "/lib/libcoff",
  52.                        (const char *) NULL),
  53.                    false);
  54.     }
  55.   }
  56.   ldfile_output_architecture = bfd_arch_i960;
  57. }
  58.  
  59. #else    /* not GNU960 */
  60.  
  61. static void gld960_before_parse()
  62. {
  63.   char *env ;
  64.   env =  getenv("G960LIB");
  65.   if (env) {
  66.     ldfile_add_library_path(env, false);
  67.   }
  68.   env = getenv("G960BASE");
  69.   if (env)
  70.     ldfile_add_library_path (concat (env, "/lib", (const char *) NULL),
  71.                  false);
  72.   ldfile_output_architecture = bfd_arch_i960;
  73. }
  74.  
  75. #endif    /* GNU960 */
  76.  
  77.  
  78. static void
  79. gld960_set_output_arch()
  80. {
  81.   bfd_set_arch_mach(output_bfd, ldfile_output_architecture, bfd_mach_i960_core);
  82. }
  83.  
  84. static char *
  85. gld960_choose_target()
  86. {
  87. #ifdef GNU960
  88.  
  89.   output_filename = "b.out";
  90.   return bfd_make_targ_name(BFD_BOUT_FORMAT, 0);
  91.  
  92. #else
  93.  
  94.   char *from_outside = getenv(TARGET_ENVIRON);
  95.   output_filename = "b.out";
  96.  
  97.   if (from_outside != (char *)NULL)
  98.     return from_outside;
  99.  
  100.   return "coff-Intel-little";
  101.  
  102. #endif
  103. }
  104.  
  105. static char *
  106. gld960_get_script(isfile)
  107.      int *isfile;
  108. EOF
  109.  
  110. if test -n "$COMPILE_IN"
  111. then
  112. # Scripts compiled in.
  113.  
  114. # sed commands to quote an ld script as a C string.
  115. sc='s/["\\]/\\&/g
  116. s/$/\\n\\/
  117. 1s/^/"/
  118. $s/$/n"/
  119. '
  120.  
  121. cat >>e${EMULATION_NAME}.c <<EOF
  122. {                 
  123.   *isfile = 0;
  124.  
  125.   if (link_info.relocateable == true && config.build_constructors == true)
  126.     return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
  127.   else if (link_info.relocateable == true)
  128.     return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
  129.   else if (!config.text_read_only)
  130.     return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
  131.   else if (!config.magic_demand_paged)
  132.     return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
  133.   else
  134.     return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
  135. }
  136. EOF
  137.  
  138. else
  139. # Scripts read from the filesystem.
  140.  
  141. cat >>e${EMULATION_NAME}.c <<EOF
  142. {                 
  143.   *isfile = 1;
  144.  
  145.   if (link_info.relocateable == true && config.build_constructors == true)
  146.     return "ldscripts/${EMULATION_NAME}.xu";
  147.   else if (link_info.relocateable == true)
  148.     return "ldscripts/${EMULATION_NAME}.xr";
  149.   else if (!config.text_read_only)
  150.     return "ldscripts/${EMULATION_NAME}.xbn";
  151.   else if (!config.magic_demand_paged)
  152.     return "ldscripts/${EMULATION_NAME}.xn";
  153.   else
  154.     return "ldscripts/${EMULATION_NAME}.x";
  155. }
  156. EOF
  157.  
  158. fi
  159.  
  160. cat >>e${EMULATION_NAME}.c <<EOF
  161.  
  162. struct ld_emulation_xfer_struct ld_gld960coff_emulation = 
  163. {
  164.   gld960_before_parse,
  165.   syslib_default,
  166.   hll_default,
  167.   after_parse_default,
  168.   after_open_default,
  169.   after_allocation_default,
  170.   gld960_set_output_arch,
  171.   gld960_choose_target,
  172.   before_allocation_default,
  173.   gld960_get_script,
  174.   "960coff",
  175.   ""
  176. };
  177. EOF
  178.